<template>
    <el-form ref="form" label-width="80px" style="padding:20px" size="mini" label-position="left">
        <el-form-item label="原密码">
            <el-input type="password" v-model="oldpassword"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
            <el-input type="password" v-model="password" placeholder="注：请使用字母数字和下划线组合"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
            <el-input type="password" v-model="rpassword"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submit">保存</el-button>
            <el-button @click="close">取消</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import C from '#/src/common/common.js'

export default {
    name: 'changePassword',
    data() {
        return {
            oldpassword: '',
            password: '',
            rpassword: '',
        }
    },
    methods: {
        async submit() {
            if (!this.oldpassword) {
                C.error('旧密码不能为空')
                return false
            }
            if (!this.password) {
                C.error('请填写新密码')
                return false
            }
            if (!this.rpassword) {
                C.error('请再次输入密码')
                return false
            }
            var myreg = /^[a-zA-Z0-9]\w{5,17}$/
            if (!myreg.test(this.password)) {
                C.error('密码不能为中文且长度在6-18之间')
                return false
            }
            if (this.password != this.rpassword) {
                C.error('两次输入的密码不一致！')
                return false
            }

            let data = {
                oldpassword: this.oldpassword,
                password: this.password,
                rpassword: this.rpassword
            }

            let res = await C.ajax('/shop/admin/changepas', data, 'post')
            if (res) {
                C.closeBrowserWindow(res)
            }
        },
        close() {
            C.closeBrowserWindow()
        }
    },
    mounted: function() {

    }
}
</script>